﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Simple.Common.Data
{
    /// <summary>
    /// Repository
    /// </summary>
    public  interface IRepository<T> where T : class
    {
        /// <summary>
        /// Get entity by identifier
        /// </summary>
        /// <param name="id">Identifier</param>
        /// <returns>Entity</returns>
        T Find(params object[] id);

        /// <summary>
        /// Insert entity
        /// </summary>
        /// <param name="entity">Entity</param>
        int Add(T entity, bool isSubmit = true);

        /// <summary>
        /// 批量插入
        /// </summary>
        /// <param name="entityList"></param>
        /// <param name="isSubmit"></param>
        /// <returns></returns>
        int AddRange(IEnumerable<T> entityList, bool isSubmit = true);

        /// <summary>
        /// Update entity
        /// </summary>
        /// <param name="entity">Entity</param>
        int Update(T entity, bool isSubmit = true);

        /// <summary>
        /// Delete entity
        /// </summary>
        /// <param name="entity">Entity</param>
        int Delete(T entity, bool isSubmit = true);

        /// <summary>
        /// Gets a table
        /// </summary>
        IQueryable<T> Table { get; }

        /// <summary>
        /// Gets a table with "no tracking" enabled (EF feature) Use it only when you load record(s) only for read-only operations
        /// </summary>
        IQueryable<T> TableNoTracking { get; }
    }
}
